#include "GameControlHandler.h"

GameControlHandler::GameControlHandler()
{
}

GameControlHandler::~GameControlHandler()
{
}


void GameControlHandler::Init()
{
//posiziono la mappa
screen_name = glGenLists(1);
glNewList(screen_name,GL_COMPILE);

        glRotatef(-27,1,0,0);
        glScalef(2.4,2,0);
        glBegin(GL_QUADS);
              glTexCoord2f(0.0f, 1.0f);   glVertex3f(-10,-10,0);
              glTexCoord2f(0.0f, 0.0f);   glVertex3f(-10,10,0);
              glTexCoord2f(1.0f, 0.0f);   glVertex3f(10,10,0 );
              glTexCoord2f(1.0f, 1.0f);   glVertex3f(10,-10,0 );
        glEnd();
        
glEndList();


}


void GameControlHandler::Move()
{
          
         
}

void GameControlHandler::DoIdle()
{
  //punteggio di gioco  
        time_t tact;
        time(&tact);
      
        state->int_time = (int)(GAME_TIME - difftime(tact,state->time));
        
        if (state->int_time <= 0)  state->gameend = true;
         
}


void GameControlHandler::Draw_Now_Loading()
{
//disegno il menu di caricamneto
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,state->th->texNames[TEX_LOADING]);
    glCallList(screen_name);
glutSwapBuffers();
}

void GameControlHandler::Draw_Paused()
{
//disegno il menu di caricamneto
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D,state->th->texNames[TEX_PAUSED]);
        glCallList(screen_name);
glutSwapBuffers();
}

void GameControlHandler::Draw_End_Of_Game()
{
//disegno il menu di caricamneto
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
        glEnable(GL_TEXTURE_2D);

        glBindTexture(GL_TEXTURE_2D,state->th->texNames[TEX_ENDING]);
        glCallList(screen_name);
        glDisable(GL_TEXTURE_2D);
        
        //punteggio di gioco  
        char p[20];  
        sprintf(p,"%d",state->score);
        glColor3f(0.8,0.1,0.1); 
        
        glRasterPos3f(-3,0,3);
        for (char *c=RESULT_STRING; *c != '\0'; c++) 
            glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *c);
        
        for (char *c=p; *c != '\0'; c++) 
           glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *c);
        

        
glutSwapBuffers();

}


void GameControlHandler::Get_Pause_time()
{
  time(&(state->pausetime));
}


void GameControlHandler::Set_Pause_time()
{
   time_t tact;
   time(&tact);
   state->time += tact-state->pausetime;
}

